home *** CD-ROM | disk | FTP | other *** search
/ Programming an RTS Game with Direct3D / Programming an RTS Game with Direct3D.iso / Examples / Chapter 5 / Example 5.6 / object.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-29  |  1.3 KB  |  59 lines

  1. #include "object.h"
  2.  
  3. std::vector<MESH*> objectMeshes;
  4. ID3DXLine *line = NULL;
  5.  
  6. HRESULT LoadObjectResources(IDirect3DDevice9* Device)
  7. {
  8.     MESH *tile = new MESH("Objects/tile.x", Device);
  9.     objectMeshes.push_back(tile);
  10.  
  11.     MESH *house = new MESH("Objects/house.x", Device);
  12.     objectMeshes.push_back(house);
  13.  
  14.     MESH *house2 = new MESH("Objects/house2.x", Device);
  15.     objectMeshes.push_back(house2);
  16.  
  17.     MESH *park = new MESH("Objects/park.x", Device);
  18.     objectMeshes.push_back(park);
  19.  
  20.     D3DXCreateLine(Device, &line);
  21.  
  22.     return S_OK;
  23. }
  24.  
  25. void UnloadObjectResources()
  26. {
  27.     for(int i=0;i<objectMeshes.size();i++)
  28.         objectMeshes[i]->Release();
  29.  
  30.     objectMeshes.clear();
  31.  
  32.     line->Release();
  33. }
  34.  
  35. //////////////////////////////////////////////////////////////////////////////
  36. //                            OBJECT CLASS                                    //
  37. //////////////////////////////////////////////////////////////////////////////
  38.  
  39. OBJECT::OBJECT()
  40. {
  41.     m_type = 0;
  42. }
  43.  
  44. OBJECT::OBJECT(int t, D3DXVECTOR3 pos, D3DXVECTOR3 rot, D3DXVECTOR3 sca)
  45. {
  46.     m_type = t;
  47.     m_meshInstance.SetPosition(pos);
  48.     m_meshInstance.SetRotation(rot);
  49.     m_meshInstance.SetScale(sca);
  50.     m_meshInstance.SetMesh(objectMeshes[m_type]);
  51.  
  52.     m_bBox = m_meshInstance.GetBoundingBox();
  53.     m_bSphere = m_meshInstance.GetBoundingSphere();
  54. }
  55.  
  56. void OBJECT::Render()
  57. {
  58.     m_meshInstance.Render();
  59. }